package am.NotenProgramm.Frame.Panels;

import java.awt.Component;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import am.NotenProgramm.Frame.*;
import am.NotenProgramm.objects.Grade;
import am.NotenProgramm.objects.Subject;
import am.NotenProgramm.objects.myDate;

public class GradeSettingsPanel extends JPanel{

	JPanel panelLeft = new JPanel();
	JPanel panelRight = new JPanel();
	
	//PANELRIGHT
	
	JLabel[] labelInfo = {new JLabel(GradePro.rb.getString("infoLine1")),
							new JLabel(GradePro.rb.getString("infoLine2")),
							new JLabel(GradePro.rb.getString("infoLine3")),
							new JLabel(GradePro.rb.getString("infoLine4")),
							new JLabel(GradePro.rb.getString("infoLine5")),
							new JLabel(GradePro.rb.getString("infoLine6")),
							new JLabel(GradePro.rb.getString("infoLine7")),
							new JLabel(GradePro.rb.getString("infoLine8"))};
	//PANELLEFT
	
	JSpinner spinnerOralWeight = new JSpinner(new SpinnerNumberModel(1,0,1,0.05));
	JSpinner spinnerSubjectWeight = new JSpinner(new SpinnerNumberModel(1,0,10,0.5));
	JLabel labelOralWeight = new JLabel(GradePro.rb.getString("oralWeight") + ":");
	JLabel labelSubjectWeight = new JLabel(GradePro.rb.getString("subjectWeight") + ":");
	float oralWeight = 0.2f;
	float subjectWeight = 1.0f;
	int subjectNr;
	
	ChangeListener changer = new ChangeListener() {
		@Override
		public void stateChanged(ChangeEvent e) {
			oralWeight = Float.parseFloat(spinnerOralWeight.getValue().toString());
			subjectWeight = Float.parseFloat(spinnerSubjectWeight.getValue().toString());
			GradePro.myProfile.getSubjects()[subjectNr].setOralWeight(oralWeight);
			GradePro.myProfile.getSubjects()[subjectNr].setSubjectWeight(subjectWeight);;
			GradePro.mainFrame.panelStatistics.refresh();
			GradePro.mainFrame.panelGrades.refreshInfoBox();
			GradePro.myStream.saveProfile(GradePro.myProfile);
		}
	};
	
	public GradeSettingsPanel(int subject) {
		setLayout(new GridLayout(1,2,10,10));
		
		subjectNr = subject;
		spinnerOralWeight.setValue(GradePro.myProfile.getSubjects()[subjectNr].getOralWeight());
		spinnerSubjectWeight.setValue(GradePro.myProfile.getSubjects()[subjectNr].getSubjectWeight());
		
		initPanelRight();
		initPanelLeft();
		
		add(panelLeft);
		add(panelRight);
		
		panelLeft.setBorder(BorderFactory.createTitledBorder(GradePro.rb.getString("buttonSettings")));
		panelRight.setBorder(BorderFactory.createTitledBorder(GradePro.rb.getString("information")));
	
	}

	
	
	private void initPanelLeft() { //SETTINGS
		panelLeft.setLayout(new GridLayout(5,2));
		panelLeft.add(labelOralWeight);
		panelLeft.add(spinnerOralWeight);
		panelLeft.add(labelSubjectWeight); 
		panelLeft.add(spinnerSubjectWeight);
		panelLeft.add(new JPanel()); //for more settings in the future?
		panelLeft.add(new JPanel());
		panelLeft.add(new JPanel());
		panelLeft.add(new JPanel());
		panelLeft.add(new JPanel());
		panelLeft.add(new JPanel());
		
		spinnerOralWeight.addChangeListener(changer);
		spinnerSubjectWeight.addChangeListener(changer);
	}

	

	private void initPanelRight() { 
		panelRight.setLayout(new GridLayout(10,1));
		panelRight.add(labelInfo[0]);
		panelRight.add(labelInfo[1]);
		panelRight.add(labelInfo[2]);
		panelRight.add(labelInfo[3]);
		panelRight.add(labelInfo[4]);
		panelRight.add(labelInfo[5]);
		panelRight.add(labelInfo[6]);
		panelRight.add(labelInfo[7]);
	}


}
